<?php
if (!defined('ROOT_PATH')) die('No direct access.');
	if ((isset($param[2])) && (isset($param[3])) && ($param[1]=='a')) view_toko($param[2]);
	else if (isset($param[1])){
		if (isset($_SESSION['logged'])){
			switch ($param[1]){
				case 'buka':
					$nama_toko = $_POST['nama-toko'];
					$alamat_toko = $_POST['alamat-toko'];
					$desc_toko = $_POST['desc-toko'];
					$fb_toko = $_POST['fb-toko'];
					$idfb = $_SESSION['logged']['id'];
					openToko($idfb,$fb_toko,$nama_toko,$alamat_toko,$desc_toko);
					header('Location: ' . $_SERVER['HTTP_REFERER']);	//redirect ke halaman sebelumnya
					break;
				case 'tambah':
					if(isset($_POST['tambah_form'])){
						$nama = $_POST['nama-barang'];
						$berat = $_POST['berat-barang'];
						$harga = $_POST['harga-barang'];
						$pre = $_POST['pre-order'];
						$kategori = $_POST['kategori'];
						$desc = $_POST['desc-barang'];
						$tag = $_POST['tag-barang'];
					}else if(isset($_POST['tambah_upload'])){
						$tmp = $_FILES['file']['tmp_name'];
						$data = new Spreadsheet_Excel_Reader($tmp);
						//echo $data->dump();
						$nama = $data->val(2,2);
						$berat = $data->val(3,2);
						$harga = $data->val(4,2);
						$desc = $data->val(5,2);
						$pre = $data->val(6,2);
						$tag = $data->val(7,2);
						$kategori = $data->val(8,2);
					}
					$id = $_SESSION['logged']['index'];
					addBarang($id,$nama,$berat,$harga,$desc,$pre,$tag,$kategori);
					header('Location: ' . $_SERVER['HTTP_REFERER']);	//redirect ke halaman sebelumnya
					break;
				case 'edit':
					$nama_toko = $_POST['nama-toko'];
					$alamat_toko = $_POST['alamat-toko'];
					$desc_toko = $_POST['desc-toko'];
					$fb_toko = $_POST['fb-toko'];
					$idfb = $_POST['idfb'];
					editToko($idfb,$fb_toko,$nama_toko,$alamat_toko,$desc_toko);
					header('Location: ' . $_SERVER['HTTP_REFERER']);	//redirect ke halaman sebelumnya
					break;
				default:
					view_404();
					break;
			}
	}else
		view_404();
	}
?>
